<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" class="myinput" />
    <div class="exchange"></div>
    <script>

        var myinputEle = document.querySelector(".myinput");
        var exchangeEle = document.querySelector(".exchange");
        myinputEle.onblur = function(){
            var val = this.value;
            // console.log(val);
            var reg = /(^\d$)|(^[1-9][0-9]$)|(^[12][0-4][0-9]$)|(^1[0-9][0-9]$)|(^2[0-4][0-9]$)|(^25[0-5]$)/;
            // console.log(reg.test(val));
            if(reg.test(val)){
                exchangeEle.innerHTML = "数字在0-255之间";
            }else{
                exchangeEle.innerHTML = "数字不在0-255之间";
            }
            /* 
                0-255；
                1 、1位 ：  ^[0-9]$     ----- 0-9
                2、 2位： [1-9][0-9] ----   10---99
                3、 3位 
                        // [1-2][0-4][0-9]  ---->
                        1[0-9][0-9]  ----->100--->199
                        2[0-4][0-9]  ---->200---249
                        25[0-5]   ---- 250---255
                        // 1449 

            
            
            
             */

        }



    </script>
</body>
</html>